package org.springframework.util;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public abstract class ReflectionUtils
{
  public static FieldFilter COPYABLE_FIELDS = new FieldFilter()
  {
    public boolean matches(Field paramAnonymousField)
    {
      return (!Modifier.isStatic(paramAnonymousField.getModifiers())) && (!Modifier.isFinal(paramAnonymousField.getModifiers()));
    }
  };
  public static MethodFilter NON_BRIDGED_METHODS = new MethodFilter()
  {
    public boolean matches(Method paramAnonymousMethod)
    {
      return !paramAnonymousMethod.isBridge();
    }
  };
  public static MethodFilter USER_DECLARED_METHODS = new MethodFilter()
  {
    public boolean matches(Method paramAnonymousMethod)
    {
      return (!paramAnonymousMethod.isBridge()) && (paramAnonymousMethod.getDeclaringClass() != Object.class);
    }
  };

  public static boolean declaresException(Method paramMethod, Class<?> paramClass)
  {
    Class[] arrayOfClass = paramMethod.getExceptionTypes();
    int i = arrayOfClass.length;
    for (int j = 0; ; j++)
    {
      if (j >= i)
        return false;
      if (arrayOfClass[j].isAssignableFrom(paramClass))
        return true;
    }
  }

  public static void doWithFields(Class<?> paramClass, FieldCallback paramFieldCallback)
    throws IllegalArgumentException
  {
    doWithFields(paramClass, paramFieldCallback, null);
  }

  public static void doWithFields(Class<?> paramClass, FieldCallback paramFieldCallback, FieldFilter paramFieldFilter)
    throws IllegalArgumentException
  {
    Object localObject = paramClass;
    Field[] arrayOfField;
    int j;
    do
    {
      arrayOfField = ((Class)localObject).getDeclaredFields();
      int i = arrayOfField.length;
      j = 0;
      if (j < i)
        break;
      localObject = ((Class)localObject).getSuperclass();
    }
    while ((localObject != null) && (localObject != Object.class));
    return;
    Field localField = arrayOfField[j];
    if ((paramFieldFilter != null) && (!paramFieldFilter.matches(localField)));
    while (true)
    {
      j++;
      break;
      try
      {
        paramFieldCallback.doWith(localField);
      }
      catch (IllegalAccessException localIllegalAccessException)
      {
        throw new IllegalStateException("Shouldn't be illegal to access field '" + localField.getName() + "': " + localIllegalAccessException);
      }
    }
  }

  public static void doWithMethods(Class<?> paramClass, MethodCallback paramMethodCallback)
    throws IllegalArgumentException
  {
    doWithMethods(paramClass, paramMethodCallback, null);
  }

  public static void doWithMethods(Class<?> paramClass, MethodCallback paramMethodCallback, MethodFilter paramMethodFilter)
    throws IllegalArgumentException
  {
    int i = 0;
    Method[] arrayOfMethod = paramClass.getDeclaredMethods();
    int j = arrayOfMethod.length;
    int k = 0;
    if (k >= j)
    {
      if (paramClass.getSuperclass() == null)
        break label119;
      doWithMethods(paramClass.getSuperclass(), paramMethodCallback, paramMethodFilter);
    }
    while (true)
    {
      return;
      Method localMethod = arrayOfMethod[k];
      if ((paramMethodFilter != null) && (!paramMethodFilter.matches(localMethod)));
      while (true)
      {
        k++;
        break;
        try
        {
          paramMethodCallback.doWith(localMethod);
        }
        catch (IllegalAccessException localIllegalAccessException)
        {
          throw new IllegalStateException("Shouldn't be illegal to access method '" + localMethod.getName() + "': " + localIllegalAccessException);
        }
      }
      label119: if (paramClass.isInterface())
      {
        Class[] arrayOfClass = paramClass.getInterfaces();
        int m = arrayOfClass.length;
        while (i < m)
        {
          doWithMethods(arrayOfClass[i], paramMethodCallback, paramMethodFilter);
          i++;
        }
      }
    }
  }

  public static Field findField(Class<?> paramClass, String paramString)
  {
    return findField(paramClass, paramString, null);
  }

  public static Field findField(Class<?> paramClass1, String paramString, Class<?> paramClass2)
  {
    Object localObject = paramClass1;
    Field localField;
    if ((Object.class.equals(localObject)) || (localObject == null))
    {
      localField = null;
      label18: return localField;
    }
    Field[] arrayOfField = ((Class)localObject).getDeclaredFields();
    int i = arrayOfField.length;
    for (int j = 0; ; j++)
    {
      if (j >= i)
      {
        localObject = ((Class)localObject).getSuperclass();
        break;
      }
      localField = arrayOfField[j];
      if (((paramString == null) || (paramString.equals(localField.getName()))) && ((paramClass2 == null) || (paramClass2.equals(localField.getType()))))
        break label18;
    }
  }

  public static Method findMethod(Class<?> paramClass, String paramString)
  {
    return findMethod(paramClass, paramString, new Class[0]);
  }

  public static Method findMethod(Class<?> paramClass, String paramString, Class<?>[] paramArrayOfClass)
  {
    Object localObject = paramClass;
    Method localMethod;
    if (localObject == null)
    {
      localMethod = null;
      label9: return localMethod;
    }
    Method[] arrayOfMethod;
    label25: int i;
    if (((Class)localObject).isInterface())
    {
      arrayOfMethod = ((Class)localObject).getMethods();
      i = arrayOfMethod.length;
    }
    for (int j = 0; ; j++)
    {
      if (j >= i)
      {
        localObject = ((Class)localObject).getSuperclass();
        break;
        arrayOfMethod = ((Class)localObject).getDeclaredMethods();
        break label25;
      }
      localMethod = arrayOfMethod[j];
      if ((paramString.equals(localMethod.getName())) && ((paramArrayOfClass == null) || (Arrays.equals(paramArrayOfClass, localMethod.getParameterTypes()))))
        break label9;
    }
  }

  public static Method[] getAllDeclaredMethods(Class<?> paramClass)
    throws IllegalArgumentException
  {
    ArrayList localArrayList = new ArrayList(32);
    doWithMethods(paramClass, new MethodCallback()
    {
      public void doWith(Method paramAnonymousMethod)
      {
        ReflectionUtils.this.add(paramAnonymousMethod);
      }
    });
    return (Method[])localArrayList.toArray(new Method[localArrayList.size()]);
  }

  public static Object getField(Field paramField, Object paramObject)
  {
    try
    {
      Object localObject = paramField.get(paramObject);
      return localObject;
    }
    catch (IllegalAccessException localIllegalAccessException)
    {
      handleReflectionException(localIllegalAccessException);
      throw new IllegalStateException("Unexpected reflection exception - " + localIllegalAccessException.getClass().getName() + ": " + localIllegalAccessException.getMessage());
    }
  }

  public static void handleInvocationTargetException(InvocationTargetException paramInvocationTargetException)
  {
    rethrowRuntimeException(paramInvocationTargetException.getTargetException());
  }

  public static void handleReflectionException(Exception paramException)
  {
    if ((paramException instanceof NoSuchMethodException))
      throw new IllegalStateException("Method not found: " + paramException.getMessage());
    if ((paramException instanceof IllegalAccessException))
      throw new IllegalStateException("Could not access method: " + paramException.getMessage());
    if ((paramException instanceof InvocationTargetException))
      handleInvocationTargetException((InvocationTargetException)paramException);
    if ((paramException instanceof RuntimeException))
      throw ((RuntimeException)paramException);
    handleUnexpectedException(paramException);
  }

  private static void handleUnexpectedException(Throwable paramThrowable)
  {
    throw new IllegalStateException("Unexpected exception thrown", paramThrowable);
  }

  public static Object invokeJdbcMethod(Method paramMethod, Object paramObject)
    throws SQLException
  {
    return invokeJdbcMethod(paramMethod, paramObject, new Object[0]);
  }

  public static Object invokeJdbcMethod(Method paramMethod, Object paramObject, Object[] paramArrayOfObject)
    throws SQLException
  {
    try
    {
      Object localObject = paramMethod.invoke(paramObject, paramArrayOfObject);
      return localObject;
    }
    catch (IllegalAccessException localIllegalAccessException)
    {
      handleReflectionException(localIllegalAccessException);
      throw new IllegalStateException("Should never get here");
    }
    catch (InvocationTargetException localInvocationTargetException)
    {
      while (true)
      {
        if ((localInvocationTargetException.getTargetException() instanceof SQLException))
          throw ((SQLException)localInvocationTargetException.getTargetException());
        handleInvocationTargetException(localInvocationTargetException);
      }
    }
  }

  public static Object invokeMethod(Method paramMethod, Object paramObject)
  {
    return invokeMethod(paramMethod, paramObject, new Object[0]);
  }

  public static Object invokeMethod(Method paramMethod, Object paramObject, Object[] paramArrayOfObject)
  {
    try
    {
      Object localObject = paramMethod.invoke(paramObject, paramArrayOfObject);
      return localObject;
    }
    catch (Exception localException)
    {
      handleReflectionException(localException);
    }
    throw new IllegalStateException("Should never get here");
  }

  public static boolean isEqualsMethod(Method paramMethod)
  {
    int i = 1;
    if ((paramMethod == null) || (!paramMethod.getName().equals("equals")))
      i = 0;
    Class[] arrayOfClass;
    do
    {
      return i;
      arrayOfClass = paramMethod.getParameterTypes();
    }
    while ((arrayOfClass.length == i) && (arrayOfClass[0] == Object.class));
    return false;
  }

  public static boolean isHashCodeMethod(Method paramMethod)
  {
    return (paramMethod != null) && (paramMethod.getName().equals("hashCode")) && (paramMethod.getParameterTypes().length == 0);
  }

  public static boolean isPublicStaticFinal(Field paramField)
  {
    int i = paramField.getModifiers();
    return (Modifier.isPublic(i)) && (Modifier.isStatic(i)) && (Modifier.isFinal(i));
  }

  public static boolean isToStringMethod(Method paramMethod)
  {
    return (paramMethod != null) && (paramMethod.getName().equals("toString")) && (paramMethod.getParameterTypes().length == 0);
  }

  public static void makeAccessible(Constructor<?> paramConstructor)
  {
    if (((!Modifier.isPublic(paramConstructor.getModifiers())) || (!Modifier.isPublic(paramConstructor.getDeclaringClass().getModifiers()))) && (!paramConstructor.isAccessible()))
      paramConstructor.setAccessible(true);
  }

  public static void makeAccessible(Field paramField)
  {
    if (((!Modifier.isPublic(paramField.getModifiers())) || (!Modifier.isPublic(paramField.getDeclaringClass().getModifiers())) || (Modifier.isFinal(paramField.getModifiers()))) && (!paramField.isAccessible()))
      paramField.setAccessible(true);
  }

  public static void makeAccessible(Method paramMethod)
  {
    if (((!Modifier.isPublic(paramMethod.getModifiers())) || (!Modifier.isPublic(paramMethod.getDeclaringClass().getModifiers()))) && (!paramMethod.isAccessible()))
      paramMethod.setAccessible(true);
  }

  public static void rethrowException(Throwable paramThrowable)
    throws Exception
  {
    if ((paramThrowable instanceof Exception))
      throw ((Exception)paramThrowable);
    if ((paramThrowable instanceof Error))
      throw ((Error)paramThrowable);
    handleUnexpectedException(paramThrowable);
  }

  public static void rethrowRuntimeException(Throwable paramThrowable)
  {
    if ((paramThrowable instanceof RuntimeException))
      throw ((RuntimeException)paramThrowable);
    if ((paramThrowable instanceof Error))
      throw ((Error)paramThrowable);
    handleUnexpectedException(paramThrowable);
  }

  public static void setField(Field paramField, Object paramObject1, Object paramObject2)
  {
    try
    {
      paramField.set(paramObject1, paramObject2);
      return;
    }
    catch (IllegalAccessException localIllegalAccessException)
    {
      handleReflectionException(localIllegalAccessException);
      throw new IllegalStateException("Unexpected reflection exception - " + localIllegalAccessException.getClass().getName() + ": " + localIllegalAccessException.getMessage());
    }
  }

  public static void shallowCopyFieldState(Object paramObject1, final Object paramObject2)
    throws IllegalArgumentException
  {
    if (paramObject1 == null)
      throw new IllegalArgumentException("Source for field copy cannot be null");
    if (paramObject2 == null)
      throw new IllegalArgumentException("Destination for field copy cannot be null");
    if (!paramObject1.getClass().isAssignableFrom(paramObject2.getClass()))
      throw new IllegalArgumentException("Destination class [" + paramObject2.getClass().getName() + "] must be same or subclass as source class [" + paramObject1.getClass().getName() + "]");
    doWithFields(paramObject1.getClass(), new FieldCallback()
    {
      public void doWith(Field paramAnonymousField)
        throws IllegalArgumentException, IllegalAccessException
      {
        ReflectionUtils.makeAccessible(paramAnonymousField);
        Object localObject = paramAnonymousField.get(ReflectionUtils.this);
        paramAnonymousField.set(paramObject2, localObject);
      }
    }
    , COPYABLE_FIELDS);
  }

  public static abstract interface FieldCallback
  {
    public abstract void doWith(Field paramField)
      throws IllegalArgumentException, IllegalAccessException;
  }

  public static abstract interface FieldFilter
  {
    public abstract boolean matches(Field paramField);
  }

  public static abstract interface MethodCallback
  {
    public abstract void doWith(Method paramMethod)
      throws IllegalArgumentException, IllegalAccessException;
  }

  public static abstract interface MethodFilter
  {
    public abstract boolean matches(Method paramMethod);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     org.springframework.util.ReflectionUtils
 * JD-Core Version:    0.6.2
 */